package com.approval.approvalapp.center.tz;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.JsdxListBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class Jxdx1SelectAdapter extends RecyclerView.Adapter<Jxdx1SelectAdapter.Holder> {

    List<JsdxListBean> lists;
     DelClickListener listener;

    public void setLists(List<JsdxListBean> lists, DelClickListener listener) {
        this.lists = lists;
        this.listener = listener;
        notifyDataSetChanged();
    }


    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_select1, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv.setText(lists.get(position).getOrgname());

        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.del(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (lists == null) {
            return 0;
        } else {
            return lists.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv)
        ImageView iv;
        @Bind(R.id.tv)
        TextView tv;

        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface DelClickListener {
        public void del(int position);
    }
}
